﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Text; 
namespace KMS.Core
{
    using System.Data;
    using System.Data.SqlClient;

    public partial class ServiceBase<T> where T: EntityBase
    {
        public ServiceBase()
        {
           
        }

        //internal string TableName { get; private set; }

        ~ServiceBase()
        {
            //if (_db != null)
            //{
            //    if (_db.State == ConnectionState.Open)
            //    {
            //        _db.Close();
            //    }
            //    _db.Dispose();
            //    _db = null;
            //}
        }

        private string _dbConnectstring = "";

        public string DbConnectString
        {
            get
            {
                if (string.IsNullOrEmpty(_dbConnectstring))
                {
                    _dbConnectstring = Kernel.Connectstring[typeof(T).GetConnName()];
                }
                return _dbConnectstring;
            }
        }

        //private IDbConnection _db;
        //public IDbConnection Db
        //{
        //    get
        //    {
        //        if (_db == null)
        //        {
        //            _db = new SqlConnection();
        //        } 
        //        return _db;
        //    }
        //}
    }
}
